/**
 * 玩家表示,通常一个头像
 */

cc.Class({
    extends: cc.Component,
    properties: {
        header: cc.Sprite,
        placehold: cc.SpriteFrame,
        user: {
            set(newValue) {
                let {avatar} = newValue
                if (avatar) {
                    let image = new Image()
                    image.onload = () => {
                        var texture2d = new cc.Texture2D();
                        texture2d.initWithElement(image)
                        texture2d.handleLoadedTexture(false)
                        let s = new cc.SpriteFrame(texture2d)
                        this.header.spriteFrame = s

                    }
                    image.src = avatar
                } else {
                    this.header.spriteFrame = this.placehold
                }
            },
        }
    }
})